<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<!--/meta 作为公共模版分离出去-->

<title>现场挂号</title>
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<article class="page-container">
	<form  method="post" class="form form-horizontal" id="frmRegist" name="frmRegist">
		<!--------------- 发票号 ------------------->
		<div class="row cl">
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>发票号：</label>
			<div class="formControls col-xs-1 col-sm-2">
				<span>
					<input type="text" class="input-text" th:value="${invoice.invoiceNum}"  id="InvoiceNum" name="InvoiceNum">
					<p style="color: red;" th:text="${errInvoice}"></p>
				</span>				
			</div>
			<div class="formControls col-xs-1 col-sm-1 col-md-1">
				<input class="btn btn-primary radius" type="button" id="btnRegist" value="&nbsp;&nbsp;挂号&nbsp;&nbsp;">
			</div>
			<div class="formControls col-xs-2 col-sm-1 col-md-1" >
				<input class="btn btn-primary radius" type="reset" value="&nbsp;&nbsp;清空&nbsp;&nbsp;">
			</div>	
			<label class="formControls col-xs-7 col-sm-6"></label>		
		</div>
		<br>
		<div class="row cl" >
			<label class="form-label col-xs-1 col-sm-1" style="font-size:20px">挂号信息</label>
			<label class="form-label col-xs-8 col-sm-9" ></label>
			<label >看诊日期：</label>
			<label>
				<!--------------- 日期 ------------------->
				<span style="font-weight: 700">
					<span  th:text="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}"></span>
				</span>
				<input type="hidden" name="visitDate"  id="visitDate" th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}">
				
				<!--------------- 午别 ------------------->
				<span id="registNoon" style="margin-left: 25px;font-weight: 700"></span>
				<input type="hidden" id="noon" name="noon">
			</label>															
		</div>		
		<hr><br>
		<!--------------- 病历号 ------------------->
		<div class="row cl">
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>病历号：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text" class="input-text" th:value="${caseNumber}"  id="caseNumber" name="caseNumber">
			</div>
			<div class="formControls col-xs-2 col-sm-2">
				<input class="btn btn-primary radius" type="button" id="btnQuery" value="&nbsp;&nbsp;病历查询&nbsp;&nbsp;">
			</div>		
		</div>
		<!--------------- 姓名 ------------------->
		<div class="row cl">
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>姓名：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text" class="input-text" th:value="${regist.realName}" placeholder="" id="realName" name="realName">
			</div>
			<!--------------- 性别 ------------------->
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>性别：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<div class="radio-box">
					<input  type="radio" id="gender" name="gender" value="71" th:checked="${regist.gender==71 || regist.gender==null}" >
					<label>男</label>
				</div>
				<div class="radio-box">
					<input  type="radio" id="gender" name="gender" value="72" th:checked="${regist.gender==72}">
					<label>女</label>
				</div>	
			</div>
			<!--------------- 出生日期 ------------------->
			<div class="formControls col-xs-2 col-sm-2 col-md-3" >
				<label>出生日期：</label>
					<input class="input-text Wdate" type="text" autocomplete="off"  
						 style="width:180px;" name="birthDate" id="birthDate"
						 th:value="${#dates.format(regist.birthDate, 'yyyy-MM-dd')}"
						 onchange="setAgeByBirthday(this.value)"
						 onfocus="WdatePicker({dateFmt:'yyyy-MM-dd', maxDate:'%y-%M-%d'})">		
				</div>
			<!--------------- 年龄 ------------------->						
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>年龄：</label>
			<div class="formControls col-xs-1 col-sm-1">
				<input type="text" class="input-text" th:value="${regist.age}" placeholder="" id="age" name="age"
					   onchange="setByBirthdayAge(this.value)">
			</div>
			<!--------------- 年龄类别 ------------------->		
			<div class="formControls col-xs-1 col-sm-1">
				<span class="select-box">
					<select class="select" id="ageType" name="ageType" >
						<option value="岁" th:selected="${regist.ageType=='岁'}">岁</option>
						<option value="月" th:selected="${regist.ageType=='月'}">月</option>
						<option value="日" th:selected="${regist.ageType=='日'}">日</option>
					</select>
				</span>
			</div>
			
		</div>
		<!--------------- 挂号级别 ------------------->
		<div class="row cl">
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>挂号级别：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<span  class="select-box">
					<select class="select"  name="registLeID" id="registLeID">				
						<option th:each="regLevList : ${regLevList}" 
								th:value="${regLevList.id}" 
								th:text="${regLevList.registName}"
								th:selected="${regLevList.id== regist.registLeID}">
						</option>
					</select>
				</span>				
			</div>
			<!--------------- 挂号科室 ------------------->		
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>挂号科室：</label>
			
			<!--------------- 挂号科室下拉菜单 ------------------->	
			<div id='dropdown' class="ac_results"></div>	
						
			<div class="formControls col-xs-2 col-sm-2">			
				<input type="text" class="input-text" id="deptName" name="deptName" th:value="${regist.deptName}" >				
				<input type="hidden" class="input-text" id="deptID" name="deptID" th:value="${regist.deptID}">				
			</div>	
			<!--------------- 医生查询 ------------------->
			<div class="formControls col-xs-2 col-sm-2">
				<input class="btn btn-primary radius" type="button" id="btnQueryScheduling" value="&nbsp;&nbsp;医生查询&nbsp;&nbsp;">
			</div>		
		</div>	
	</form>
	<br>
	<div class="mt-20">
		<!----------------------------- Table	 --------------------------------->
		<table class="table-sort table table-border table-bordered table-bg table-hover table-responsive">
			<thead>
				<tr class="text-c">
					<th width="25">选择</th>
					<th width="80">排班日期</th>
					<th width="150">午别</th>
					<th width="120">真实姓名</th>
					<th width="120">医生职称</th>					
					<th width="150">所在科室</th>
					<th width="120">挂号级别</th>					
				</tr>
			</thead>
			<tbody>		
				<tr class="text-c" th:each="scheduling: ${schedulingList}" onclick="setRadioBox(this)">
					<td style="padding: 0">
						<input type="radio" id="userID" name="userID" th:value="${scheduling.user.id}" >
					</td>
					<td th:text="${#dates.format(scheduling.schedDate,'yyyy-MM-dd')}"></td>
					<td th:text="${scheduling.noon}"></td>
					<td class="text-l" th:text="${scheduling.user.realName}"></td>
					<td th:text="${scheduling.user.constantName}"></td>
					<td th:text="${scheduling.user.deptName}"></td>
					<td th:text="${scheduling.user.registName}"></td>
				</tr>
			</tbody>
		</table>
	</div>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript" src="/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/lib/datatables/1.10.15/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="/selectCity/dept.js"></script>
<script type="text/javascript" src="/selectCity/dimensions.js"></script>
<script type="text/javascript" src="/selectCity/suggest.js"></script>
<script type="text/javascript">

$('.table-sort').dataTable({
	"lengthMenu": [5, 10, 25, 50],//表格左上角下拉菜单
	"order": [ [ 2, "desc" ] ],//默认第几个排序
	"bStateSave": true,//状态保存
	"paging":true,//设置分页状态  true为默认值
	"searching":true,//设置查找状态  true为默认值
	"aoColumnDefs": [
	  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
	  {"orderable":false,"aTargets":[0,0]}// 不参与排序的列
	]
});

//根据日期设置年龄
function setAgeByBirthday(txtValue){
	var millYear = 1000 * 60 * 60 * 24 * 365;
	var millMonth = 1000 * 60 * 60 * 24 * 30;
	var millDate = 1000 * 60 * 60 * 24;
	
	var value="";
	var type= "岁";
	if(txtValue != ''){
		//生日日期
		var ymd = txtValue.split('-');
		var birthday = new Date(ymd[0], ymd[1] - 1, ymd[2]);
		
		//当前日期
		var now = new Date();
		now = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		
		//计算年龄
		var milliseconds = now.getTime() - birthday.getTime();
		value = parseInt(milliseconds / millYear);
		if(value < 1){
			value = parseInt(milliseconds / millMonth);
			if(value < 1){
				value = parseInt(milliseconds / millDate);
				type="日";
			}else{
				type="月"
			}
		}else{
			type="岁";
		}
	}
	
	$('#age').val(value);
	$('#ageType').val(type);
}

//根据年龄判断生日
function setByBirthdayAge(txtValue){
	var millYear = 1000 * 60 * 60 * 24 * 365;
	var millMonth = 1000 * 60 * 60 * 24 * 30;
	var millDate = 1000 * 60 * 60 * 24;
	
	var milliseconds;
	
	var millNow = new Date().getTime();
	var type = $('#ageType').val();
	if(type = "岁"){
		milliseconds = millNow - txtValue * millYear;
	}else if(type="月"){
		milliseconds = millNow - txtValue * millMonth;
	}else{
		milliseconds = millNow - txtValue * millDate;
	}
	$('#birthDate').val(dateFormat(new Date(milliseconds)));
}

//转换日期格式
function dateFormat(time){
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    return year + "-" + month + "-" + date;
}

//判断午别
function amPm(date){
	return date.getHours() > 12 ? '下午': '上午';
}

//当前行radiobox选择控制
function setRadioBox(node){
	$chk = $(node).children().first().children();
	$chk.prop('checked', true);
}

$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	
	
	//设置午别
	$('#registNoon').text(amPm(new Date()));
	//设置隐藏域noon值
	$('#noon').val(amPm(new Date()));
		
	//病历查询按钮
	$('#btnQuery').click(function(){
		$('#realName').rules("remove","required");
		$('#age').rules("remove","required");
		$('#deptName').rules("remove","required");
		
		
		$('#frmRegist').attr('action','/reg/caseInfo');
		$('#frmRegist').submit();
	});
	
	//医生查询按钮
	$('#btnQueryScheduling').click(function(){
		$('#realName').rules("remove","required");
		$('#age').rules("remove","required");
		$('#deptName').rules("remove","required");
		console.log($('#deptID').val());
		
		$('#frmRegist').attr('action','/reg/schedulingInfo');
		$('#frmRegist').submit();
	});
	
	//挂号按钮
	$('#btnRegist').click(function(){
		$('#realName').rules("add", {required : true});
		$('#age').rules("add", {required : true});
		$('#deptName').rules("add", {required : true});
		
		//取得datatable中选中数据的id
		var $chks = $('[type=radio][name="userID"]:checked');
		var userid = $chks.val();
		console.log('userid='+userid);
		$('#frmRegist').attr('action','/reg/doRegist?userid='+userid);
		$('#frmRegist').submit();
	});
	
	//挂号科室下拉菜单
	$(function(){
		//选择科室后向dataContainer中设置value
		$("#deptName").suggest(citys, {hot_list:commoncitys, attachObject: "#dropdown",dataContainer:'#deptID'});
	});
	
			
	$("#frmRegist").validate({
		rules:{
			realName:{
				required:true,
				minlength:1,
				maxlength:16
			},
			sex:{
				required:true,
			},
			invoiceID:{
				required:true,				
			},
			caseNumber:{
				required:true,		
			},
			age:{
				required:true,
			},
			registLeID:{
				required:true,
			},
			deptName:{
				required:true,
			}		
			
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){			
			//$(form).ajaxSubmit(); 
			//	以上写法表单验证通过后会自动提交
			//	应改写为以下方式，否则，button按钮提交表单之后，表单会提交两次，前端造成stack 溢出
			form.submit(); 
		}
		
	});
});




</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>